<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery.js" charset="utf-8"></script> <!-- 引入jquery插件 -->
    <script>
        /*     
        //一.Promise基础用法
         let p = new Promise((resolve, reject) => {
                 // resolve('成功')
                 reject('失败')
             })
             // 方法1
             // p.then(res => {
             //     console.log(res, '方法1');
             // }, (error) => {
             //     console.log(error, 'error');
             // })
     
             // 方法2
     
             p.then((res) => {
                 console.log(res, '成功');
             }).catch((error) => {
                 console.log(error, '失败');
             }).finally(() => {
                 console.log('不管成功失败都会走这一步');
             }) */

        // 二.Promise内部要的是异步请求结果，ajax,定时器等-实际运用用它封装网络请求$.ajax(),wx.request() 
        /*      let p = new Promise((resolve, reject) => {
                 $.ajax({
                     url: 'data/1.json',
                     //method: 'get',
                     // data:{}
                     success: function (res) {
                         console.log(res, '成功');
                         resolve(res)
                     },
                     error: function (error) {
                         console.log(error);
                         reject(error, '失败')
                     }
                 })
             })
     
             p.then(res => {
                 console.log(res, 200);
             }).catch(error => {
                 console.log(error, 500);
             }).finally(() => {
                 console.log('11111');
             }) */

           //  三.Promise封装-axios原理
    /*        function getAxis() {
               return new Promise((resolve, reject) => {
                   $.ajax({
                       url: 'url',
                       //method: 'get',
                       // data:{}
                       success: function (res) {
                           console.log(res, '成功');
                           resolve(res)
                       },
                       error: function (error) {
                           console.log(error);
                           reject(error, '失败')
                       }
                   })
               })
           } */
            //   //调用promise
            //    getAxis('data/1.json').then(res => {
            //        console.log(res);
            //    })  

        //解决方法1-请求多个结果，在内层判断
   /*      let data1 = getAxis('data/1json')
        let data2 = getAxis('data/2json')
        Promise.all([data1, data2]).then(res => {
            console.log(都执行);
            let [a, b] = res
            console.log(a, b);
        }).catch((error) => {
            console.log(error);
        }) */
    </script>
</head>

<body>

</body>

</html>